package com.xcity.game.pet.template;

import java.util.List;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 宠物技能
 * @author yang.li
 *
 */
@Excel(value = "pet.xlsx", sheet = 1)
public class PetSkillTemplate extends Template {

	/** 类型 */
	protected byte type;

	/** 技能名 */
	protected String name;

	/** 描述（大括号表示一个变量[可以不需要]，{0}表示效果值1，{1}表示效果值2，...以此类推） */
	protected String desc;
	
	protected List<PetSkillLevelUpTemplate> levelUpTemplates;

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public List<PetSkillLevelUpTemplate> getLevelUpTemplates() {
		return levelUpTemplates;
	}

	@Binding(type = PetSkillLevelUpTemplate.class, field = "id", ref = "id")
	public void setLevelUpTemplates(List<PetSkillLevelUpTemplate> levelUpTemplates) {
		this.levelUpTemplates = levelUpTemplates;
	}
	
	public PetSkillLevelUpTemplate getLevelUpTemplate(int level) {
		List<PetSkillLevelUpTemplate> temps = levelUpTemplates;
		if (temps == null || temps.isEmpty()) {
			return null;
		}
		if (level < 1) {
			level = 1;
		} else if (level > temps.size()) {
			level = temps.size();
		}
		return temps.get(level - 1);
	}

	@Override
	public void validate() throws TemplateException {}
}
